//
//  CJYCSwitchView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/6/13.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CJYCSwitchView.h"

@implementation CJYCSwitchView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        NSArray *nibView =  [[NSBundle mainBundle] loadNibNamed:@"CJYCSwitchView"owner:self options:nil];
        self = [nibView objectAtIndex:0];
        self.lineView.frame = CGRectMake(_LeftButton.frame.origin.x,self.frame.size.height-2, _LeftButton.frame.size.width, 1);
        self.lineView.backgroundColor = SELECTEDCOLOR;
        [_LeftButton setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
        [_LeftButton setTitleColor:TITLECOLOR forState:UIControlStateNormal];
    }
    return self;
}
- (IBAction)leftClick:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
        self->_lineView.center = CGPointMake(self->_LeftButton.center.x, self.frame.size.height-2);
    }];
    _LeftButton.selected = YES;
    _RightButton.selected = NO;
    [_LeftButton setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
    [_RightButton setTitleColor:TITLECOLOR forState:UIControlStateNormal];
    self.upBlock();
}
- (IBAction)rightClick:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
        self->_lineView.center = CGPointMake(self->_RightButton.center.x, self.frame.size.height-2);
    }];
    _LeftButton.selected = NO;
    _RightButton.selected = YES;
    [_RightButton setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
    [_LeftButton setTitleColor:TITLECOLOR forState:UIControlStateNormal];
    self.downBlock();
}

@end
